using System.Collections.Generic;
using System.Text;

namespace OracleInternal.SqlAndPlsqlParser.LocalParsing
{
	internal class OracleLpSelectTermAll : OracleLpSelectTerm
	{
		protected OracleLpName m_vParentObjectName;

		protected OracleLpName m_vSchemaName;

		public OracleLpName ParentObjectName
		{
			get
			{
				return m_vParentObjectName;
			}
			set
			{
				m_vParentObjectName = value;
			}
		}

		public OracleLpName SchemaName
		{
			get
			{
				return m_vSchemaName;
			}
			set
			{
				m_vSchemaName = value;
			}
		}

		public OracleLpSelectTermAll(OracleLpSelectClause sc)
			: base(sc)
		{
			m_vType = OracleLpSelectTermType.ALL;
		}

		public override void Resolve()
		{
			OracleLpQueryBlock oracleLpQueryBlock = m_vParent.Parent as OracleLpQueryBlock;
			m_vColumnDescriptors = new List<OracleLpColumnDescriptor>();
			if (m_vParentObjectName == null)
			{
				foreach (OracleLpStatementDataContainer term in oracleLpQueryBlock.FromClause.Terms)
				{
					term.ColumnDescriptors.ForEach(delegate(OracleLpColumnDescriptor cd)
					{
						if (cd.IsShowing)
						{
							m_vColumnDescriptors.Add(cd);
						}
					});
				}
				return;
			}
			IOracleLpColumnDescriptorContainer oracleLpColumnDescriptorContainer = oracleLpQueryBlock.FromClause.FindColumnContainer(m_vSchemaName, m_vParentObjectName);
			if (oracleLpColumnDescriptorContainer == null)
			{
				throw new OracleLpException(OracleLpExceptionType.MissingReference, OracleLpExceptionError.MissingTable_View_Query, string.Format(OracleLpErrorStrings.GetErrorString(OracleLpExceptionError.MissingTable_View_Query), (m_vSchemaName == null) ? "*" : (m_vSchemaName.DbName ?? "*"), m_vParentObjectName.DbName));
			}
			oracleLpColumnDescriptorContainer.ColumnDescriptors.ForEach(delegate(OracleLpColumnDescriptor cd)
			{
				if (cd.IsShowing)
				{
					m_vColumnDescriptors.Add(cd);
				}
			});
		}

		internal override void ToString(StringBuilder sb)
		{
			string depthIndent = base.DepthIndent;
			sb.Append(depthIndent);
			sb.Append("All columns (*)");
			sb.Append("  Parent Object: ");
			sb.Append((m_vParentObjectName == null) ? "none" : (m_vParentObjectName.DbName ?? "none"));
			sb.Append("  Schema: ");
			sb.Append((m_vSchemaName == null) ? "none" : (m_vSchemaName.DbName ?? "none"));
			sb.Append('\n');
		}
	}
}
